﻿using System;
using System.Collections.Generic;
using System.Text;
using Castle.Services.Transaction;
using MiragePWF.NH.Logging;
using MiragePWF.NH.Repositories;
using MiragePWF.NH.UOW;
using NHibernate.Criterion;
using NHibernate.SqlCommand;
using Wolfut.MirageEE.Domain.Common;
using Wolfut.MirageEE.Interface.Common;
using Wolfut.MirageEE.Kernal.Common;

namespace Wolfut.MirageEE.Server.Server.Common
{
    [Transactional]
    [AutoLogging]
    public class CurrencyCategoryService : BusinessServiceBase,ICurrencyCategoryService
    {
        private readonly IRepository<CurrencyCategory> currencyCategoryRepository;
        public CurrencyCategoryService(IRepository<CurrencyCategory> currencyCategoryRepository)
        {
            this.currencyCategoryRepository = currencyCategoryRepository;
        }

   
        #region ICurrencyCategory Members

        [Transaction(TransactionMode.Requires)]
        public CurrencyCategory AddOrUpdateCurrencyCategory(CurrencyCategory currencyCategory)
        {
            currencyCategoryRepository.Save(currencyCategory);
            return currencyCategory;
        }                                       
 
        public IList<CurrencyCategory> GetCurrencyCategory(string currencyCode, string currencyName, bool isDeleted)
        {
            
            DetachedCriteria criteria = DetachedCriteria.For(typeof (CurrencyCategory));
         if(!string.IsNullOrEmpty(currencyCode))
         {
             criteria.Add(Expression.Eq("CurrencyCode", currencyCode));
             
         }
         if (!string.IsNullOrEmpty(currencyName))
         {
             criteria.Add(Expression.Like("currencyName", currencyCode,MatchMode.Anywhere));

         }
         criteria.Add(Expression.Eq("IsDeleted", isDeleted));
         return currencyCategoryRepository.FindAll(criteria);
        }

        #endregion
    }
}
